//
//  CZBaseTableViewController.swift
//  CZWeibo007
//
//  Created by Vize on 16/2/17.
//  Copyright © 2016年 Vize. All rights reserved.
//

import UIKit

class CZBaseTableViewController: UITableViewController,CZVistorViewDelegate {

    var userLogin = false
    
    override func loadView() {
        userLogin ? super.loadView() : setupVistorView()
    }
    
    
    //设置一个访客视图
    func setupVistorView() {
        //设置一个view
        view = vistorView
        
        //设置代理
        vistorView.delegate = self
        
        //设置左边和右边导航栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginClick")
        
//        view.backgroundColor = UIColor.brownColor()
        if self is CZHomeViewController {
            
            //动画
            vistorView.startRotationAnimation()
            
            //设置退出后台和进入后台都会通知
            //设置通知
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            
            
        }else if self is CZMessageViewController {
            vistorView.setVistorInfo("visitordiscover_image_message", message: "随便写1")
        }else if self is CZDiscoveryViewController {
            vistorView.setVistorInfo("visitordiscover_image_message", message: "随便写2")
            
        }else if self is CZProfileViewController {
            vistorView.setVistorInfo("visitordiscover_image_profile", message: "随便写3")
        }
        
        
        
    }
    
    // MARK: - 实现代理方法
    func visitorViewLoginClick() {
        print(__FUNCTION__)
    }
    func visitorViewRegisterClick() {
        print(__FUNCTION__)
    }
    
    // MARK: - 通知
    //推到后台
    func didEnterBackground() {
        //停止转轮旋转
        vistorView.pauseAnimation()
        print(__FUNCTION__)
        
    }

    ///进入前台
    func didBecomeActive() {
        
        //继续转到转轮
        vistorView.resumeAnimation()
        print(__FUNCTION__)
        
    }
    
    lazy var vistorView:CZVistorView = CZVistorView()
}
